﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CosAging;
using CosAging.Windows;
using Org.BouncyCastle.Asn1.Crmf;
using Org.BouncyCastle.Crmf;
using Timer = System.Timers.Timer;

namespace CosAging.View
{
    /// <summary>
    /// SystemMonitor.xaml 的交互逻辑
    /// </summary>
    public partial class SystemMonitor1 : UserControl
    {

        public static double PixelCoefficient = 1;
        public int CurrentID;
        public Timer BeginTimer = new Timer(); public Timer ReadTimer = new Timer();
        public Timer UpdateTimer1 = new Timer();
        public static string NameSelected;

        public SystemMonitor1()
        {
            //PublicClass.计时起点();
            InitializeComponent();
            Class_Initialize();
            this.DataContext = PublicClass.CosBobject;
            //ProgressBegin();
            //PublicClass.计时终点();
            //PublicClass.Logger.Info(PublicClass.时间差);

        }
        private void ProgressBegin()
        {

            //Thread thread = new Thread(new ThreadStart(() =>
            //{
            //    for (int i = 0; i <= 100; i++)
            //    {
            //        this.progressBar1.Dispatcher.BeginInvoke((ThreadStart)delegate { this.progressBar1.Value = i; });
            //        Thread.Sleep(100);
            //    }

            //}));
            //thread.Start();
        }
        private void Class_Initialize()
        {
            try
            {
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 33; j++)
                    {
                        Style GD_style = new Style();
                        GD_style = (Style)FindResource("LabelContent");
                      
                        Label LB = new Label();
                        LB.Background = new SolidColorBrush(Colors.Transparent);
                        LB.Style = GD_style;
                        LB.Foreground= new SolidColorBrush(Colors.Black);
                        LB.FontSize = 13 * PixelCoefficient;
                        LB.HorizontalContentAlignment = HorizontalAlignment.Center;
                        //LB.FontWeight = FontWeights.Bold;
                        //LB.HorizontalAlignment = HorizontalAlignment.Stretch;
                        //LB.VerticalAlignment = VerticalAlignment.Stretch;
                        //LB.HorizontalContentAlignment = HorizontalAlignment.Center;
                        //LB.VerticalContentAlignment = VerticalAlignment.Center;
                        ////LB.Height = 30 * PixelCoefficient;
                        ////LB.Width = 80 * PixelCoefficient;
                        //LB.FontSize = 17 * PixelCoefficient;
                        //LB.Margin = new Thickness(0, 0, 0, 0);
                        //LB.FontFamily = new FontFamily("宋体");

                        Binding binding = new Binding();
                        //准备Binding
                        if (j == 0)
                        {
                            LB.FontSize = 15 * PixelCoefficient;
                            binding.Source = PublicClass.CosBobject.CD测试单元格[i];
                            binding.Path = new PropertyPath("通道号");
                        }
                        else if(j == 1)
                        {
                            binding.Source = PublicClass.CosBobject.CD测试单元格[i];
                            binding.Path = new PropertyPath("电流");
                        }
                        else if (j >1 & j<32)
                        {
                            binding.Source = PublicClass.CosBobject.CD测试单元格[i].CD测试芯片[j-2];
                            binding.Path = new PropertyPath("温度");
                        }
                        else if (j == 32)
                        {
                            LB.FontSize = 15 * PixelCoefficient;
                            binding.Source = PublicClass.CosBobject.CD测试单元格[i];
                            binding.Path = new PropertyPath("结束时间");
                        }
                

                        //使用Binding 连接数据源与Bingding目标
                        BindingOperations.SetBinding(LB, Label.ContentProperty, binding);//使用binding实例将数据源与目标关联起来
                        /* BindingOperations.SetBinding(LB, Label.NameProperty, binding2);*///使用binding实例将数据源与目标关联起来
                                                                                        //BindingOperations.SetBinding(LB, Label.ForegroundProperty, binding3);//使用binding实例将数据源与目标关联起来
                        MainGrid.Children.Add(LB);
                        Grid.SetRow(LB, i+2);
                        Grid.SetColumn(LB, j);
                        Grid.SetColumnSpan(LB, 1);
                        //PB.HorizontalAlignment = HorizontalAlignment.Stretch;
                          
                           
                        }
                    }

                for (int i = 10; i < 18; i++)
                {
                    for (int j = 0; j < 33; j++)
                    {
                        Style GD_style = new Style();
                        GD_style = (Style)FindResource("LabelContent");

                        Label LB = new Label();
                        LB.Background = new SolidColorBrush(Colors.Transparent);
                        LB.Style = GD_style;
                        LB.Foreground = new SolidColorBrush(Colors.Black);
                        LB.FontSize = 13 * PixelCoefficient;
                        LB.HorizontalContentAlignment = HorizontalAlignment.Center;
                        //LB.FontWeight = FontWeights.Bold;
                        //LB.HorizontalAlignment = HorizontalAlignment.Stretch;
                        //LB.VerticalAlignment = VerticalAlignment.Stretch;
                        //LB.HorizontalContentAlignment = HorizontalAlignment.Center;
                        //LB.VerticalContentAlignment = VerticalAlignment.Center;
                        ////LB.Height = 30 * PixelCoefficient;
                        ////LB.Width = 80 * PixelCoefficient;
                        //LB.FontSize = 17 * PixelCoefficient;
                        //LB.Margin = new Thickness(0, 0, 0, 0);
                        //LB.FontFamily = new FontFamily("宋体");

                        Binding binding = new Binding();
                        //准备Binding
                        if (j == 0)
                        {
                            LB.FontSize = 15 * PixelCoefficient;
                            binding.Source = PublicClass.CosBobject.CD测试单元格[i-10];
                            binding.Path = new PropertyPath("通道号");
                        }
                        else if (j == 1)
                        {
                            binding.Source = PublicClass.CosBobject.CD测试单元格[i-10];
                            binding.Path = new PropertyPath("电流");
                        }
                        else if (j > 1 & j < 32)
                        {
                            binding.Source = PublicClass.CosBobject.CD测试单元格[i-10].CD测试芯片[j - 2];
                            binding.Path = new PropertyPath("功率");
                        }
                        else if (j == 32)
                        {
                            LB.FontSize = 15 * PixelCoefficient;
                            binding.Source = PublicClass.CosBobject.CD测试单元格[i-10];
                            binding.Path = new PropertyPath("结束时间");
                        }


                        //使用Binding 连接数据源与Bingding目标
                        BindingOperations.SetBinding(LB, Label.ContentProperty, binding);//使用binding实例将数据源与目标关联起来
                        /* BindingOperations.SetBinding(LB, Label.NameProperty, binding2);*///使用binding实例将数据源与目标关联起来
                                                                                            //BindingOperations.SetBinding(LB, Label.ForegroundProperty, binding3);//使用binding实例将数据源与目标关联起来
                        MainGrid.Children.Add(LB);
                        Grid.SetRow(LB, i + 2);
                        Grid.SetColumn(LB, j);
                        Grid.SetColumnSpan(LB, 1);
                        //PB.HorizontalAlignment = HorizontalAlignment.Stretch;
                    }
                }

                //if (App.Dic.ContainsKey("SplashWindow"))
                //{
                //    SplashWindow sw = App.Dic["SplashWindow"] as SplashWindow;///在PublicClass有定义程序开始先打开SplashWindow窗口
                //    sw.Dispatcher.Invoke((Action)(() => sw.Close()));//在sw的线程上关闭SplashWindow

                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                PublicClass.NLOGex(ex);
            }

        }


    }
}
